﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RoboticOperationMerge.CUiROMSelectOperationsForm
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing;
using System.Resources;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.RoboticOperationMerge;

public class CUiROMSelectOperationsForm : TxForm
{
  private ITxObject m_targetOperation;
  private ITxObject m_sourceOperation;
  private TxTypeFilterValidator m_commonTypeFilterValidator;
  private TxCompositeValidator m_commonTypeTargetFilterValidator;
  private bool m_acceptChanges;
  private Point m_defaultLocation;
  private bool m_shouldUseDefaultLocation;
  private IContainer components;
  private Button m_okButton;
  private Button m_cancelButton;
  private Label m_targetLabel;
  private TxObjEditBoxCtrl m_targetOperationEditBox;
  private Label label1;
  private TxObjEditBoxCtrl m_sourceOperationEditBox;

  public CUiROMSelectOperationsForm()
  {
    this.InitializeComponent();
    this.m_commonTypeFilterValidator = (TxTypeFilterValidator) null;
    this.m_commonTypeTargetFilterValidator = (TxCompositeValidator) null;
    this.InitializeValidators();
    this.m_acceptChanges = false;
    this.m_targetOperation = (ITxObject) null;
    this.m_sourceOperation = (ITxObject) null;
    Point location = ((Form) this).Location;
    int x = location.X;
    location = ((Form) this).Location;
    int y = location.Y;
    this.m_defaultLocation = new Point(x, y);
    this.m_shouldUseDefaultLocation = false;
  }

  public bool AcceptChanges
  {
    get => this.m_acceptChanges;
    set => this.m_acceptChanges = value;
  }

  public ITxObject TargetOperation
  {
    get => this.m_targetOperation;
    set => this.m_targetOperation = value;
  }

  public ITxObject SourceOperation
  {
    get => this.m_sourceOperation;
    set => this.m_sourceOperation = value;
  }

  public Point DefaultLocation
  {
    get => this.m_defaultLocation;
    set => this.m_defaultLocation = value;
  }

  public bool ShouldUseDefaultLocation
  {
    get => this.m_shouldUseDefaultLocation;
    set => this.m_shouldUseDefaultLocation = value;
  }

  public virtual void OnInitTxForm()
  {
    base.OnInitTxForm();
    if (!this.m_shouldUseDefaultLocation)
      return;
    ((Form) this).Location = this.m_defaultLocation;
  }

  public void Show(ITxObject targetOp, ITxObject sourceOp, bool shouldGetSelectedOperation)
  {
    this.m_targetOperation = targetOp == null ? (!shouldGetSelectedOperation ? (ITxObject) null : this.GetSelectedOperationAsTarget()) : targetOp;
    this.m_sourceOperation = sourceOp;
    this.m_targetOperationEditBox.Object = this.m_targetOperation;
    this.m_sourceOperationEditBox.Object = this.m_sourceOperation;
    this.RegisterForEvents();
    this.UpdateOkButtonEnabler();
    ((Control) this).Show();
    if (this.m_targetOperation != null && this.m_sourceOperation == null)
      this.m_sourceOperationEditBox.Focus();
    else
      this.m_targetOperationEditBox.Focus();
  }

  private ITxObject GetSelectedOperationAsTarget()
  {
    ITxObject operationAsTarget = (ITxObject) null;
    TxSelection activeSelection = TxApplication.ActiveSelection;
    if (activeSelection != null)
    {
      TxObjectList items = activeSelection.GetItems();
      if (items != null && ((Collection<ITxObject>) items).Count == 1)
      {
        ITxObject itxObject = ((Collection<ITxObject>) items)[0];
        if (itxObject != null)
        {
          string str = (string) null;
          if (this.m_commonTypeTargetFilterValidator != null && this.m_commonTypeTargetFilterValidator.IsValidObject(itxObject, ref str))
            operationAsTarget = itxObject;
        }
      }
    }
    return operationAsTarget;
  }

  private void InitializeValidators()
  {
    // ISSUE: unable to decompile the method.
  }

  private void RegisterForEvents()
  {
    this.m_targetOperationEditBox.ListenToPick = true;
    this.m_targetOperationEditBox.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.m_targetOperationEditBox_Picked);
    this.m_targetOperationEditBox.TypeValid += new EventHandler(this.m_targetOperationEditBox_TypeValid);
    this.m_targetOperationEditBox.TypeInvalid += new EventHandler(this.m_targetOperationEditBox_TypeInvalid);
    ((Control) this.m_targetOperationEditBox).LostFocus += new EventHandler(this.m_targetOperationEditBox_LostFocus);
    this.m_sourceOperationEditBox.ListenToPick = true;
    this.m_sourceOperationEditBox.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.m_sourceOperationEditBox_Picked);
    this.m_sourceOperationEditBox.TypeValid += new EventHandler(this.m_sourceOperationEditBox_TypeValid);
    this.m_sourceOperationEditBox.TypeInvalid += new EventHandler(this.m_sourceOperationEditBox_TypeInvalid);
    ((Control) this.m_sourceOperationEditBox).LostFocus += new EventHandler(this.m_sourceOperationEditBox_LostFocus);
  }

  private ResourceManager GetResourceManager()
  {
    return new ResourceManager("DnProcessSimulateCommands.RoboticOperationMerge.Res.ResourceTable", ((object) this).GetType().Assembly);
  }

  private void UpdateOkButtonEnabler()
  {
    bool flag = false;
    try
    {
      if (this.m_targetOperation != null)
      {
        if (this.m_sourceOperation != null)
        {
          string str = (string) null;
          if (this.m_commonTypeFilterValidator.IsValidObject(this.m_targetOperation, ref str))
          {
            if (this.m_commonTypeFilterValidator.IsValidObject(this.m_sourceOperation, ref str))
              flag = true;
          }
        }
      }
    }
    catch (Exception ex)
    {
      flag = false;
    }
    this.m_okButton.Enabled = flag;
  }

  private void m_okButton_Click(object sender, EventArgs e)
  {
    this.m_acceptChanges = false;
    if (this.m_targetOperation != null && this.m_sourceOperation != null)
    {
      if (this.m_targetOperation != this.m_sourceOperation)
      {
        string str = (string) null;
        if (this.m_commonTypeFilterValidator.IsValidObject(this.m_targetOperation, ref str) && this.m_commonTypeFilterValidator.IsValidObject(this.m_sourceOperation, ref str))
        {
          if (this.AreOperationsCompatible())
          {
            ITxObject itxObject1 = this.m_targetOperation;
            ITxObject itxObject2 = this.m_sourceOperation;
            if (this.m_targetOperation is TxRoboticSeamOperation)
            {
              itxObject1 = (ITxObject) this.m_targetOperation.Collection;
              itxObject2 = (ITxObject) this.m_sourceOperation.Collection;
            }
            ITxRoboticOrderedCompoundOperation compoundOperation1 = itxObject1 as ITxRoboticOrderedCompoundOperation;
            ITxRoboticOrderedCompoundOperation compoundOperation2 = itxObject2 as ITxRoboticOrderedCompoundOperation;
            if (compoundOperation1 != null && compoundOperation2 != null)
            {
              if (compoundOperation1.Robot == compoundOperation2.Robot)
              {
                this.m_acceptChanges = true;
              }
              else
              {
                this.m_targetOperation.GetType();
                TxMessageBox.Show(this.GetResourceManager().GetString("WARNING_DIFFERENT_ROBOTS"), this.GetResourceManager().GetString("WARNING_CAPTION"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
              }
            }
            else if (compoundOperation1 == null && compoundOperation2 == null)
              this.m_acceptChanges = true;
          }
          else
            TxMessageBox.Show(this.GetResourceManager().GetString("WARNING_DIFFERENT_OPERATION_TYPES"), this.GetResourceManager().GetString("WARNING_CAPTION"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
        }
      }
      else
        TxMessageBox.Show(this.GetResourceManager().GetString("WARNING_SAME_TARGET_SOURCE"), this.GetResourceManager().GetString("WARNING_CAPTION"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
    }
    if (!this.m_acceptChanges)
      return;
    ((Form) this).Close();
  }

  private void m_cancelButton_Click(object sender, EventArgs e)
  {
    this.m_acceptChanges = false;
    ((Form) this).Close();
  }

  private bool AreOperationsCompatible()
  {
    bool flag = false;
    Type type1 = this.m_targetOperation.GetType();
    Type type2 = this.m_sourceOperation.GetType();
    if (type1 != (Type) null && type2 != (Type) null && type1.Equals(type2))
    {
      if (this.m_targetOperation is TxGenericRoboticOperation)
      {
        if (((TxBaseGenericRoboticOperation) (this.m_targetOperation as TxGenericRoboticOperation)).ProcessType.Equals("PICK_AND_PLACE_OPERATION"))
        {
          if (((TxBaseGenericRoboticOperation) (this.m_sourceOperation as TxGenericRoboticOperation)).ProcessType.Equals("PICK_AND_PLACE_OPERATION"))
            flag = true;
        }
        else if (!((TxBaseGenericRoboticOperation) (this.m_sourceOperation as TxGenericRoboticOperation)).ProcessType.Equals("PICK_AND_PLACE_OPERATION"))
          flag = true;
      }
      else
        flag = true;
    }
    return flag;
  }

  private void m_targetOperationEditBox_Picked(object sender, TxObjEditBoxCtrl_PickedEventArgs e)
  {
    this.m_targetOperation = this.m_targetOperationEditBox.Object;
    if (this.m_targetOperation != null && this.m_sourceOperation == null)
      this.m_sourceOperationEditBox.Focus();
    this.UpdateOkButtonEnabler();
  }

  private void m_targetOperationEditBox_TypeValid(object sender, EventArgs e)
  {
    this.m_targetOperation = this.m_targetOperationEditBox.Object;
    this.UpdateOkButtonEnabler();
  }

  private void m_targetOperationEditBox_TypeInvalid(object sender, EventArgs e)
  {
    this.m_targetOperation = (ITxObject) null;
    this.UpdateOkButtonEnabler();
  }

  private void m_targetOperationEditBox_LostFocus(object sender, EventArgs e)
  {
    this.m_targetOperationEditBox.HideErrorWindow();
  }

  private void m_sourceOperationEditBox_Picked(object sender, TxObjEditBoxCtrl_PickedEventArgs e)
  {
    this.m_sourceOperation = this.m_sourceOperationEditBox.Object;
    if (this.m_sourceOperation != null && this.m_targetOperation == null)
      this.m_targetOperationEditBox.Focus();
    this.UpdateOkButtonEnabler();
  }

  private void m_sourceOperationEditBox_TypeValid(object sender, EventArgs e)
  {
    this.m_sourceOperation = this.m_sourceOperationEditBox.Object;
    this.UpdateOkButtonEnabler();
  }

  private void m_sourceOperationEditBox_TypeInvalid(object sender, EventArgs e)
  {
    this.m_sourceOperation = (ITxObject) null;
    this.UpdateOkButtonEnabler();
  }

  private void m_sourceOperationEditBox_LostFocus(object sender, EventArgs e)
  {
    this.m_sourceOperationEditBox.HideErrorWindow();
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiROMSelectOperationsForm));
    this.m_okButton = new Button();
    this.m_cancelButton = new Button();
    this.m_targetLabel = new Label();
    this.m_targetOperationEditBox = new TxObjEditBoxCtrl();
    this.m_sourceOperationEditBox = new TxObjEditBoxCtrl();
    this.label1 = new Label();
    ((Control) this).SuspendLayout();
    componentResourceManager.ApplyResources((object) this.m_okButton, "m_okButton");
    this.m_okButton.Name = "m_okButton";
    this.m_okButton.UseVisualStyleBackColor = true;
    this.m_okButton.Click += new EventHandler(this.m_okButton_Click);
    this.m_cancelButton.DialogResult = DialogResult.Cancel;
    componentResourceManager.ApplyResources((object) this.m_cancelButton, "m_cancelButton");
    this.m_cancelButton.Name = "m_cancelButton";
    this.m_cancelButton.UseVisualStyleBackColor = true;
    this.m_cancelButton.Click += new EventHandler(this.m_cancelButton_Click);
    componentResourceManager.ApplyResources((object) this.m_targetLabel, "m_targetLabel");
    this.m_targetLabel.Name = "m_targetLabel";
    this.m_targetOperationEditBox.ListenToPick = false;
    componentResourceManager.ApplyResources((object) this.m_targetOperationEditBox, "m_targetOperationEditBox");
    ((Control) this.m_targetOperationEditBox).Name = "m_targetOperationEditBox";
    this.m_targetOperationEditBox.Object = (ITxObject) null;
    this.m_targetOperationEditBox.PickLevel = (TxPickLevel) 1;
    this.m_targetOperationEditBox.PickOnly = false;
    this.m_targetOperationEditBox.ReadOnly = false;
    this.m_targetOperationEditBox.ValidatorType = (TxValidatorType) 10;
    this.m_sourceOperationEditBox.ListenToPick = false;
    componentResourceManager.ApplyResources((object) this.m_sourceOperationEditBox, "m_sourceOperationEditBox");
    ((Control) this.m_sourceOperationEditBox).Name = "m_sourceOperationEditBox";
    this.m_sourceOperationEditBox.Object = (ITxObject) null;
    this.m_sourceOperationEditBox.PickLevel = (TxPickLevel) 1;
    this.m_sourceOperationEditBox.PickOnly = false;
    this.m_sourceOperationEditBox.ReadOnly = false;
    this.m_sourceOperationEditBox.ValidatorType = (TxValidatorType) 10;
    componentResourceManager.ApplyResources((object) this.label1, "label1");
    this.label1.Name = "label1";
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Control) this).Controls.Add((Control) this.label1);
    ((Control) this).Controls.Add((Control) this.m_sourceOperationEditBox);
    ((Control) this).Controls.Add((Control) this.m_targetOperationEditBox);
    ((Control) this).Controls.Add((Control) this.m_targetLabel);
    ((Control) this).Controls.Add((Control) this.m_cancelButton);
    ((Control) this).Controls.Add((Control) this.m_okButton);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedSingle;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiROMSelectOperationsForm);
    ((Form) this).ShowIcon = false;
    ((Control) this).ResumeLayout(false);
  }
}
